/*
Copyright (C) 2014 Infinite Automation Systems Inc. All rights reserved.
@author Matthew Lohbihler
*/
package com.serotonin.m2m2.virtual.vo;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Arrays;
import java.util.List;
import com.serotonin.json.spi.JsonProperty;
import com.serotonin.m2m2.i18n.TranslatableMessage;
import com.serotonin.m2m2.rt.event.type.AuditEventType;
import com.serotonin.m2m2.virtual.rt.ChangeTypeRT;
import com.serotonin.m2m2.virtual.rt.RandomMultistateChangeRT;
public class RandomMultistateChangeVO extends ChangeTypeVO {
public static final TranslatableMessage KEY = new TranslatableMessage("dsEdit.virtual.changeType.random");
@JsonProperty
private int[] values = new int[0];
@Override
public int typeId() {
return Types.RANDOM_MULTISTATE;
}
@Override
public TranslatableMessage getDescription() {
return KEY;
}
@Override
public ChangeTypeRT createRuntime() {
return new RandomMultistateChangeRT(this);
}
public int[] getValues() {
return values;
}
public void setValues(int[] values) {
this.values = values;
}
@Override
public void addProperties(List<TranslatableMessage> list) {
super.addProperties(list);
AuditEventType.addPropertyMessage(list, "dsEdit.virtual.values", Arrays.toString(values));
}
@Override
public void addPropertyChanges(List<TranslatableMessage> list, Object o) {
super.addPropertyChanges(list, o);
RandomMultistateChangeVO from = (RandomMultistateChangeVO) o;
if (Arrays.equals(from.values, values))
AuditEventType.addPropertyChangeMessage(list, "dsEdit.virtual.values", Arrays.toString(from.values),
Arrays.toString(values));
}
//
//
// Serialization
//
private static final long serialVersionUID = -1;
private static final int version = 1;
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeInt(version);
out.writeObject(values);
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
int ver = in.readInt();
// Switch on the version of the class so that version changes can be elegantly handled.
if (ver == 1) {
values = (int[]) in.readObject();
}
}
}